package com.party.admin.biz.advertise;


import com.party.core.utils.MyBeanUtils;
import com.party.core.model.advertise.Advertise;
import com.party.core.service.advertise.IAdvertiseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 广告业务控制服务
 * Created by wei.li
 *
 * @date 2017/3/22 0022
 * @time 17:44
 */
@Service
public class AdvertiseBizService {

    @Autowired
    IAdvertiseService advertiseService;



    /**
     * 保存广告业务
     *
     * @param entity 广告信息
     * @throws Exception 异常信息
     */
    public void saveBiz(Advertise entity) throws Exception {

        //编辑表单保存
        if(StringUtils.isNotBlank(entity.getId())){

            //从数据库取出记录的值
            Advertise ad = advertiseService.get(entity.getId());

            //将编辑表单中的非\NULL值覆盖数据库记录中的值
            MyBeanUtils.copyBeanNotNull2Bean(entity, ad);

            //保存
            advertiseService.update(ad);
        }else{

            //新增表单保存
            advertiseService.insert(entity);

            //保存
        }
    }
}
